﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EstimateLib
{
    public class EstimateServer
    {

        DomainNameLength lenEstimater = new DomainNameLength();

        DomainNameMeaningEstimater meaningEstimater = new DomainNameMeaningEstimater();

        DomainSufixEstimater sufixEstimater = new DomainSufixEstimater();

        public EstimateResult Estimate(string FullName)
        {
            if (string.IsNullOrEmpty(FullName))
            {
                throw new Exception("FullName for estimate can not be null!");
            }

            string MainName = GetMainName(FullName);
            string Sufix = GetSurfix(FullName);

            DomainNameLengthLevel lenLevel = lenEstimater.CaculateDomainNameLengthLevel(MainName.Length);

            DomainNameMeaningLevel meanLevel = meaningEstimater.CalculateDomainNameMeaningLevel(MainName);

            DomainSufixLevel surfixLevel = sufixEstimater.CaculateDomainSufixLevel(Sufix);

            return new EstimateResult(lenLevel, meanLevel, surfixLevel);
        }

        private string GetSurfix(string FullName)
        {
            int dotIndex = FullName.IndexOf('.');

            if (dotIndex < 0 || dotIndex == FullName.Length - 1)
            {
                throw new Exception("FullName has not a surfix!");
            }

            return FullName.Substring(dotIndex + 1, FullName.Length - dotIndex - 1);

        }

        private string GetMainName(string FullName)
        {
            int dotIndex = FullName.IndexOf('.');

            if (dotIndex < 0 || dotIndex == FullName.Length - 1)
            {
                throw new Exception("FullName has not a MainName!");
            }

            return FullName.Substring(0, dotIndex);
        }


    }
}


